package com.bupt.liutong.front.bbs.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.bupt.liutong.admin.bbs.bo.BoardBo;
import com.bupt.liutong.admin.bbs.bo.PostBo;
import com.bupt.liutong.admin.bbs.form.BoardForm;
import com.bupt.liutong.admin.bbs.form.PostForm;
import com.bupt.liutong.admin.core.base.BaseAction;

public class BoardAction extends BaseAction {

	private BoardBo boardBo;
	private PostBo postBo;

	public ActionForward list(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		BoardForm boardForm = (BoardForm) form;
		boardForm.setEnabled(1);
		request.setAttribute("boardFormList", boardBo.getBoards(boardForm));
		return mapping.findForward("list");
	}

	public ActionForward postList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		BoardForm boardForm = (BoardForm) form;
		boardForm.setEnabled(1);
		request.setAttribute("boardFormList", boardBo.getBoards(boardForm));
		
		PostForm postForm = new PostForm();
		postForm.setBoardId(boardForm.getId());
		postForm.setSearchFlag(boardForm.getSearchFlag());
		postForm.setParentId(new Long(-1));
		postForm.setPageSize(8);
		postForm.setCurPage(boardForm.getCurPage());
		postForm.setTotalRow(boardForm.getTotalRow());
		request.setAttribute("postFormList", postBo.getPostsByPage(postForm, request));
		putPageInfo(request, postForm);
		return mapping.findForward("postList");
	}
	
	public void setBoardBo(BoardBo boardBo) {
		this.boardBo = boardBo;
	}

	public void setPostBo(PostBo postBo) {
		this.postBo = postBo;
	}
}
